package org.item.customer.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import org.item.common.bean.Customers;
import org.item.common.bean.Product;
import org.item.common.service.ICustomerService;
import org.item.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("customer")
public class CustomerController {
    @Autowired
    ICustomerService customerService;

    @PostMapping("/")
    public ResultData insert(@RequestBody Customers customers){
        Customers data= customerService.insert(customers);
        return ResultData.success(data);
    }

    @PutMapping("/")
    public ResultData update(@RequestBody Customers customers){
        Customers data= customerService.update(customers);
        return  ResultData.success(data);
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result=customerService.delete(id);
        if(result>=1){
            return ResultData.success(200,"删除成功",null);
        }else {
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getById(@PathVariable Integer id){
        Customers customers=customerService.getById(id);
        return ResultData.success(customers);
    }
    @GetMapping("/page")
    public ResultData getListByPage(IPage page, @RequestBody Customers customers){
        IPage data=customerService.getListByPage(page, customers);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getLsit(Customers customers){
        List<Customers> data=customerService.getList(customers);
        return ResultData.success(data);
    }

}
